#define  _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>


typedef int ElemType;
typedef struct {
	ElemType* data;
	int elemlen;
}SSTable;


void IinitSstabe(SSTable &s,int x)
{
	s.elemlen = x;
	s.data =(ElemType*)malloc(sizeof(ElemType) * s.elemlen);
	for (int i = 0; i < s.elemlen; i++)
	{
		s.data[i] = rand() % 100 ;
	}
}
void PrintSstabe(SSTable s)
{
	for (int i = 0; i < s.elemlen; i++)
	{
		printf("%3d", s.data[i]);
	}
	printf("\n");
}
void swap(int &x,int &y)
{
	int temp = x;
	x = y;
	y = temp;
}
void BubbleSort(SSTable &s)
{
	bool flag =true;
	for (int i = 0; i < s.elemlen-1; i++)
	{
		for (int j = 1; j < s.elemlen-i; j++)
		{
			if (s.data[j-1]>s.data[j])
			{
				flag = false;
				swap(s.data[j-1], s.data[j]);
			}
		}
		if (flag)
		{
			return;
		}
	}

}
int main()
{
	srand((unsigned)time(NULL));
	SSTable S;
	IinitSstabe(S,20);
	PrintSstabe(S);

	BubbleSort(S);
	PrintSstabe(S);

	return 0;
}